﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    public class nhz
    {


        public static  void nhzxty()

        {
            try
            {
                string constr = "Server=.;uid=sa;pwd=12345678;database=Djjj;";
                SqlConnection sqlConnection = new SqlConnection(constr);
                sqlConnection.Open();
                string sql = "select * from xxx";
                SqlCommand mycom = new SqlCommand(sql, sqlConnection);
                SqlDataReader myda = mycom.ExecuteReader();
                for (int i = 0; i < myda.FieldCount; i++)
                {
                    Console.Write(myda.GetName(i) + "\t");


                }
                Console.WriteLine();

                while (myda.Read())
                {
                    for (int i = 0; i < myda.FieldCount; i++)
                    {

                        Console.Write(myda[i].ToString() + "\t");

                    }
                    Console.WriteLine();
                }


            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message.ToString());
            }
            finally
            {

            }
        }
        public  void Xtyzg()
        {
            try
            {
                string constr = "Server=.;uid=sa;pwd=12345678;database=Djjj;";
                SqlConnection sqlConnection = new SqlConnection(constr);
                sqlConnection.Open();
                string sql = "select * from xxx";
                SqlDataAdapter mysd = new SqlDataAdapter(sql, sqlConnection);
                DataSet myds = new DataSet();
                mysd.Fill(myds, "staff");
                foreach (DataTable table in myds.Tables)
                {
                    foreach (DataColumn clo in table.Columns)


                        Console.Write(clo.ColumnName + "\t");
                    Console.WriteLine();
                    foreach (DataRow row in table.Rows)
                    {

                        foreach (DataColumn clo in table.Columns)
                            Console.Write(row[clo] + "\t");
                        Console.WriteLine();
                    }

                }
            
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message.ToString ());
            }
            finally
            {

            }
        }
    }
}
